import express from 'express';
// 导入 cors 中间件 解决跨域问题
import cors from 'cors';

// 引入文件
import uploadFile from './upload/uploadFile.ts';
import getFileRecords from './upload/fileRecord.ts'
import consumptionRecords from './consumption/consumptionRecord.ts';
import categoryDataDetail from './dataAnalysis/categoryDetail.ts'
import singlePurchaseRanking from './dataAnalysis/singlePurchaseRanking.ts'
import consumptionRatio from './dataAnalysis/consumptionRatio.ts'
import calendarShowData from './dataAnalysis/calendarView.ts';
import changeIgnore from './consumption/changeIgnore.ts';
import deleteConsumption from './consumption/deleteConsumption.ts';
import addAssetRecord from './asset/addAssetRecord.ts';
import getAllFundInfo from './asset/getAllFund.ts';
import updateFundInfo from './asset/updateFunds.ts';
import getCurFundInfo from './asset/getCurFund.ts';
import clearFundPrincipal from './asset/deleteFundPrincipal.ts';
import inquireAssetRecord from './asset/assetRecords.ts';

const app = express();
const port = 8080;

// 将 cors 注册为全局中间件 
app.use(cors())

// 配置解析表单数据的中间件
app.use(express.json());
// app.use(express.urlencoded({ extended: false }))

// 注册，需要传参三个account,code,mail，post请求
// 为 /api/uploadFile 路由单独应用 express.urlencoded 中间件
app.use('/api', express.urlencoded({ extended: false }), uploadFile);

app.use('/api', getFileRecords) // 查看文件上传记录-获取文件记录
app.use('/api', consumptionRecords) // 查看消费记录-获取消费记录
app.use('/api', categoryDataDetail) // 数据分析-消费类名TOP
app.use('/api', singlePurchaseRanking) // 数据分析-单次消费金额TOP
app.use('/api', consumptionRatio) // 数据分析-消费类名占比
app.use('/api', calendarShowData) // 数据分析-日历视图
app.use('/api', changeIgnore) // 消费记录-修改忽略状态
app.use('/api', deleteConsumption) // 消费记录-删除消费记录
app.use('/api', addAssetRecord) // 固资统计-添加资产记录
app.use('/api', getAllFundInfo) // 固资统计-获取所有基金信息
app.use('/api', updateFundInfo) // 固资统计-基金信息补充
app.use('/api', getCurFundInfo) // 固资统计-获取当前持有基金情况
app.use('/api', clearFundPrincipal) // 固资统计-清空基金本金（当前持有基金情况表移除信息）
app.use('/api', inquireAssetRecord) // 固资统计-查询资产记录

// 监听端口
app.listen(port, () => {
    console.log(`Server is running on http://localhost:${port}`);
});